﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using dhDataAcess.baseBLL;
using dhDataAcess.orderLinqDAL;
using dhDataAcess.dataAcess.produceDataSetTableAdapters;
using dhDataAcess.dataAcess;
using System.Data.SqlClient;
using dhDataAcess.orderDAL;
using dhDataAcess.produceLinq;
using dhDataAcess.produceDAL;
using dhDataAcess.sysDAL;
using dhDataAcess.dataAcess.ViewDataSetTableAdapters;

namespace dhSystemBLL.produceBLL
{
  public   class pdfpjlbBLL
    {
      private V_piaoranorderTableAdapter _V_piaoranorderAdapter = null;
      private V_piaoranorderTableAdapter V_piaoranorderAdapter
        {
            get
            {
                if (_V_piaoranorderAdapter == null) _V_piaoranorderAdapter = new V_piaoranorderTableAdapter ();
                return _V_piaoranorderAdapter;
            }
        }
      private pdfpjlbTableAdapter _pdfpjlbAdapter = null;
      private pdfpjlbTableAdapter pdfpjlbAdapter
        {
            get
            {
                if (_pdfpjlbAdapter == null) _pdfpjlbAdapter = new pdfpjlbTableAdapter();
                return _pdfpjlbAdapter;
            }
        }

        /// <summary>
      /// 查询胚带发胚记录表
        /// </summary>
        /// <param name="row"></param>
        /// <returns></returns>
      public produceDataSet .pdfpjlbDataTable  getpdfpjlbAll()
        {
            try
            {
                return pdfpjlbAdapter.GetDatapdfpjlbALL();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message.ToString());
            }
        }
        /// <summary>
      /// 根据漂染单号查询视图漂染单
        /// </summary>
        /// <param name="row"></param>
        /// <returns></returns>
      public ViewDataSet.V_piaoranorderDataTable getV_piaoranorderAllBybillStatus(string billStatus)
        {
            try
            {
                return V_piaoranorderAdapter.GetDataV_piaoranorderBybillStatus(billStatus);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message.ToString());
            }
        }
      /// <summary>
      /// 根据漂染单号查询视图漂染单
      /// </summary>
      /// <param name="row"></param>
      /// <returns></returns>
      public ViewDataSet.V_piaoranorderDataTable getV_piaoranorderAllBybillStatuslike(string orderDetailNo, string billStatus)
      {
          try
          {
              return V_piaoranorderAdapter.GetDataV_piaoranorderBybillStatusLike(orderDetailNo,billStatus);
          }
          catch (Exception ex)
          {
              throw new Exception(ex.Message.ToString());
          }
      }
      /// <summary>
      /// 根据漂染单号查询视图漂染单
      /// </summary>
      /// <param name="row"></param>
      /// <returns></returns>
      public ViewDataSet.V_piaoranorderDataTable getV_piaoranorderAllBybilloNo(string billoNo)
      {
          try
          {
              return V_piaoranorderAdapter.GetDataV_piaoranorderBybilloNo (billoNo);
          }
          catch (Exception ex)
          {
              throw new Exception(ex.Message.ToString());
          }
      }
      /// <summary>
      /// 根据漂染单号查询视图漂染单
      /// </summary>
      /// <param name="row"></param>
      /// <returns></returns>
      public ViewDataSet.V_piaoranorderDataTable getV_piaoranorderAllByorderDetailNo(string orderDetailNo)
      {
          try
          {
              return V_piaoranorderAdapter.GetDataV_piaoranorderByorderDetailNo(orderDetailNo);
          }
          catch (Exception ex)
          {
              throw new Exception(ex.Message.ToString());
          }
      }
      /// <summary>
      /// 根据漂染单号查询胚带发胚记录表
      /// </summary>
      /// <param name="row"></param>
      /// <returns></returns>
      public produceDataSet.pdfpjlbDataTable getpdfpjlbAllByorderDetailNo(string orderDetailNo)
      {
          try
          {
              return pdfpjlbAdapter.GetDatapdfpjlbByorderDetailNo(orderDetailNo);
          }
          catch (Exception ex)
          {
              throw new Exception(ex.Message.ToString());
          }
      }
      /// <summary>
      /// 根据发胚状态查询胚带发胚记录表
      /// </summary>
      /// <param name="row"></param>
      /// <returns></returns>
      public produceDataSet.pdfpjlbDataTable getpdfpjlbAllBybillStatus(string billStatus)
      {
          try
          {
              return pdfpjlbAdapter.GetDatalpdfpjilbBybillStatus  (billStatus);
          }
          catch (Exception ex)
          {
              throw new Exception(ex.Message.ToString());
          }
      }
        /// <summary>
      /// 插入胚带发胚记录表
        /// </summary>
        /// <param name="row"></param>
        /// <returns></returns>
      public int pdfpjlbInsert(produceDataSet .pdfpjlbDataTable pdfpjlbTable)
        {
            int i = 0;
            SqlConnection conn = dataConn.connOpen();
            SqlTransaction tn = null;
            try
            {
                tn = conn.BeginTransaction();
                pdfpjlbDAL pdfpjlb = new pdfpjlbDAL(tn, conn);
                pdfpjlb.pdfpjlbInsertII(pdfpjlbTable);
                tn.Commit();
                return i;

            }
            catch (SqlException ex)
            {
                tn.Rollback();
                if (ex.Number == 2627)
                {
                    throw new Exception("这个发胚记录已经存在");
                }


                throw new Exception(ex.Number.ToString() + ex.Message.ToString());

            }
            catch (Exception ex)
            {
                tn.Rollback();
                throw new Exception(ex.Message.ToString());

            }
            finally
            {
                conn.Close();
            }
        }
        /// <summary>
      /// 更新胚带发胚记录表
        /// </summary>
        /// <param name="row"></param>
        /// <returns></returns>
      public int pdfpjlbUpdate(pdfpjlbModel row)
        {
            int i = 0;
            SqlConnection conn = dataConn.connOpen();
            SqlTransaction tn = null;
            try
            {
                tn = conn.BeginTransaction();
                pdfpjlbDAL pdfpjlb = new pdfpjlbDAL(tn, conn);
                pdfpjlb.pdfpjlbUpdate (row);
                tn.Commit();
                return i;
            }
            catch (Exception ex)
            {
                tn.Rollback();
                throw new Exception(ex.Message.ToString());

            }
            finally
            {
                conn.Close();
            }
        }
        /// <summary>
        /// 删除一行胚带发胚记录表
        /// </summary>
        /// <param name="row"></param>
        /// <returns></returns>
      public int pdfpjlbDel(string billNo)
        {
            int i = 0;
            SqlConnection conn = dataConn.connOpen();
            SqlTransaction tn = null;
            try
            {
                tn = conn.BeginTransaction();
                pdfpjlbDAL pdfpjlb = new pdfpjlbDAL(tn, conn);
                pdfpjlb.pdfpjlbDelII(billNo);
                tn.Commit();
                return i;
            }
            catch (Exception ex)
            {
                tn.Rollback();
                throw new Exception(ex.Message.ToString());

            }
            finally
            {
                conn.Close();
            }
        }
    }
}
